// 初始路由
import error from '@/pageStatus/error.vue'
import noAuth from '@/pageStatus/noAuth.vue'
import notFound from '@/pageStatus/notFound.vue'
import loading from '@/pageStatus/loading.vue'

import index from '@/pages/index.vue'
const register = () => defineAsyncComponent(() => import('@/pages/register/index.vue'))
// vue3.0异步组件
const asyncPageWithOptionsVue3 = () => import('@/pages/layout/index.vue')

const userInfo = defineAsyncComponent({
    // 异步组件// success
    loader: () => import('@/pages/userInfo/index.vue'),
    delay: 200,
    timeout: 30000,
    errorComponent: error,
    loadingComponent: loading
})

export const initRoutes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/pages/login/index.vue') // vue2.0异步组件动态导入
    },
    {
        path: '/register',
        name: 'register',
        component: register
    }
]

export const statusRoutes = [
    // 状态提示
    {
        path: '/loading',
        component: loading,
        meta: {
            title: '加载中'
        }
    },
    {
        path: '/500',
        component: error,
        meta: {
            title: '500'
        }
    },
    {
        path: '/503',
        component: noAuth,
        meta: {
            title: '503'
        }
    },
    {
        path: '/404',
        component: notFound,
        meta: {
            title: '404'
        }
    },
    // 匹配任意路由
    {
        path: '/:catchAll(.*)',
        component: notFound
    }
]

export const routes = [
    {
        path: '/layout',
        name: 'layout',
        // vue3.0异步组件,更高级的声明方式
        component: asyncPageWithOptionsVue3,
        children: [
            // {
            //     path: '/demo',
            //     name: 'demo',
            //     component: index
            // },
            // {
            //     path: '/home',
            //     name: 'home',
            //     component: () => import('@/pages/home/index.vue')
            // },
            // {
            //     path: '/system/todayAppointment',
            //     name: 'systemTodayAppointment',
            //     component: () => import('@/pages/todayAppointment/index.vue')
            // }
            {
                path: '/userInfo',
                name: 'userInfo',
                component: userInfo
            }
        ]
    },
    ...initRoutes,
    ...statusRoutes
]
